# syntax=docker/dockerfile:1
FROM maven:3.9.6-eclipse-temurin-17 AS build
WORKDIR /app

# 复制父POM和common模块
COPY ../pom.xml ./
COPY ../common ./common

# 复制当前服务
COPY . ./code-completion-service

# 构建
RUN mvn -q -f code-completion-service/pom.xml clean package -DskipTests

FROM eclipse-temurin:17-jre
WORKDIR /app

# 复制JAR文件
COPY --from=build /app/code-completion-service/target/*.jar app.jar

# 设置环境变量
ENV SPRING_PROFILES_ACTIVE=docker
ENV JAVA_OPTS="-Xms512m -Xmx2048m -XX:+UseG1GC"

# 暴露端口
EXPOSE 8081

# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
  CMD curl -f http://localhost:8081/actuator/health || exit 1

# 启动应用
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]
